export default {
	data() {
		return {
			Images: ["jpg", "jpeg", "png", "gif", "bmp"],
			Zips: ["zip", "rar", "7z"],
			Videos: ["avi", "mp4", "rmvb", "flv", "mov", "m2v", "mkv"],
			Audios: ["mp3", "wav", "wmv", "wma"],
			Excels: ["xls", "xlsx"],
			Words: ["doc", "docx"],
			Pdfs: ["pdf"],
			Ppts: ["ppt"],
			Txts: ["txt"],
		}
	},
	computed: {
		imageAble: function() {
			return this.isImage(this.material);
		},
		videoAble: function() {
			return this.isVideo(this.material);
		},
		officeAble: function() {
			return this.isOffice(this.material);
		}
	},
	methods: {
		isImage: function(material) {
			if (material) {
				let _suffix = this.getSuffix(material);
				return this.Images.includes(_suffix);
			}
			return false;
		},
		isVideo: function(material) {
			if (material) {
				let _suffix = this.getSuffix(material);
				return this.Videos.includes(_suffix) ||
					this.Audios.includes(_suffix);
			}
			return false;
		},
		isOffice: function(material) {
			if (material) {
				let _suffix = this.getSuffix(material);
				return this.Excels.includes(_suffix) ||
					this.Words.includes(_suffix) ||
					this.Pdfs.includes(_suffix) ||
					this.Ppts.includes(_suffix) ||
					this.Txts.includes(_suffix);
			}
			return false;
		},
		getSuffix: function(file) {
			if (!(file && file.id)) {
				return "";
			}
			let _name = file.name;
			let _suffix = ((_name && _name.lastIndexOf(".") > -1) ?
				_name.substring(_name.lastIndexOf(".") + 1, _name.length) : '').toLowerCase();
			return _suffix;
		},
		getFileImage: function(file) {
			let _path = "";
			if (file.type === 1) {
				_path = require("../images/folder@2x.png");
				return _path;
			}
			let _suffix = this.getSuffix(file);
			if (!_suffix) {
				_path = require("../images/file_none@2x.png");
				return _path;
			}
			if (this.Images.includes(_suffix)) {
				_path = require("../images/file_img@2x.png");
			} else if (this.Zips.includes(_suffix)) {
				_path = require("../images/file_zip@2x.png");
			} else if (this.Videos.includes(_suffix)) {
				_path = require("../images/file_video@2x.png");
			} else if (this.Audios.includes(_suffix)) {
				_path = require("../images/file_mp3@2x.png");
			} else if (this.Excels.includes(_suffix)) {
				_path = require("../images/file_excel@2x.png");
			} else if (this.Words.includes(_suffix)) {
				_path = require("../images/file_docx@2x.png");
			} else if (this.Pdfs.includes(_suffix)) {
				_path = require("../images/file_pdf@2x.png");
			} else if (this.Ppts.includes(_suffix)) {
				_path = require("../images/file_ppt@2x.png");
			} else if (this.Txts.includes(_suffix)) {
				_path = require("../images/file_txt@2x.png");
			} else {
				_path = require("../images/file_none@2x.png");
			}
			return _path;
		},
	},
	filters: {
		size: function(value) {
			if (!value) {
				return "0 Bytes";
			}
			let unitArr = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
			let index = 0,
				srcsize = parseFloat(value);
			index = Math.floor(Math.log(srcsize) / Math.log(1024));
			let size = srcsize / Math.pow(1024, index);
			size = size.toFixed(2);
			return size + unitArr[index];
		}
	}
}
